<template>
  <div class="login-page flex justify-center items-center">
    <div class="log"><icons class="icon" name="logo" /></div>
    <input class="input" v-model="params.UserName" placeholder="输入账号" />
    <input
      class="input"
      v-model="params.Pwd"
      type="password"
      placeholder="输入密码"
    />
    <div class="btn" @click="loginFun">登录</div>
  </div>
</template>

<script lang="ts" setup>
import { computed, ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { LoginByPwd } from "@/server"; //导入登录函数
import { useAppStore } from "@/store/modules/user";
const store = useAppStore();
const router = useRouter();
const params = ref({
  UserName: "", //用户名
  Pwd: "", //登录密码
});
/**
 * @description: 登录接口调用示例
 * @return {*}
 * @author: cool panda
 */
const loginFun = async () => {
  const { UserName, Pwd } = params.value;
  if (!UserName || !Pwd) {
    store.warning("账号密码不能为空"); // 错误提示
    return false;
  }
  const res: any = await LoginByPwd(params.value);
  if (res.Tag === 1) {
    console.log("登录成功");
    store.setToken(res.Data.Id);
    toPage("/");
  } else {
    store.error(res.Message); // 错误提示
  }
};
/**
 * @description: 页面跳转实例
 * @param {*} url
 * @return {*}
 * @author: cool panda
 */
const toPage = (url: string) => {
  router.push(url);
};
onMounted(() => {
  console.log("dom构建完成");
});
</script>
<style lang="less" scoped>
.login-page {
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 100px);
  background-color: #ffffff;
  flex-direction: column;
  .log {
    .icon {
      width: 300px;
    }
    margin-bottom: 60px;
  }
  .input {
    width: 400px;
    height: 40px;
    margin: 15px;
    padding: 5px;
  }

  .btn {
    margin-top: 60px;
    cursor: pointer;
    width: 200px;
    height: 40px;
    font-size: 16px;
    border-radius: 4px;
    background-color: rgb(41, 178, 57);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    margin-bottom: 30px;
  }
}
</style>
